home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktimeintro / play movie w.controller / common files / comframework.h < prev    next >
Encoding:
Text File  |  2000-10-06  |  11.3 KB  |  330 lines

  1. //////////
  2. //
  3. //    File:        ComFramework.h
  4. //
  5. //    Contains:    Code for the QuickTime sample code framework that is common to both Macintosh and Windows. 
  6. //
  7. //    Written by:    Tim Monroe
  8. //                Based on the QTShell code written by Tim Monroe, which in turn was based on the MovieShell
  9. //                code written by Kent Sandvik (Apple DTS). This current version is now very far removed from
  10. //                MovieShell.
  11. //
  12. //    Copyright:    © 1999 by Apple Computer, Inc., all rights reserved.
  13. //
  14. //    Change History (most recent first):
  15. //       
  16. //       <2>         01/14/00    rtm        added fGraphicsImporter field to window object record
  17. //       <1>         11/05/99    rtm        first file
  18. //
  19. //////////
  20.  
  21. #pragma once
  22.  
  23.  
  24. //////////
  25. //       
  26. // header files
  27. //       
  28. //////////
  29.  
  30. #ifndef __Prefix_File__
  31. #include <WinPrefix.h>
  32. #endif
  33.  
  34. #ifndef __CONTROLDEFINITIONS__
  35. #include <ControlDefinitions.h>
  36. #endif
  37.  
  38. #ifndef __FILETYPESANDCREATORS__
  39. #include <FileTypesAndCreators.h>
  40. #endif
  41.  
  42. #ifndef __MOVIES__
  43. #include <Movies.h>
  44. #endif
  45.  
  46. #ifndef __NAVIGATION__
  47. #include <Navigation.h>
  48. #endif
  49.  
  50. #ifndef __QUICKTIMEVR__
  51. #include <QuickTimeVR.h>
  52. #endif
  53.  
  54. #ifndef __RESOURCES__
  55. #include <Resources.h>
  56. #endif
  57.  
  58. #ifndef __SOUND__
  59. #include <Sound.h>
  60. #endif
  61.  
  62. #ifndef _STRING_H
  63. #include <string.h>
  64. #endif
  65.  
  66. #ifndef __TEXTUTILS__
  67. #include <TextUtils.h>
  68. #endif
  69.  
  70. #ifndef __QTUtilities__
  71. #include "QTUtilities.h"
  72. #endif
  73.  
  74. #include "ComResource.h"
  75.  
  76. #if TARGET_OS_WIN32
  77. #ifndef __QTML__
  78. #include <QTML.h>
  79. #endif
  80.  
  81. #include <shlobj.h>                                            // for SHAddToRecentDocs
  82. #endif
  83.  
  84. // revert to older names, to keep the linker happy
  85. #if TARGET_CPU_68K
  86. #define EnableMenuItem                        EnableItem
  87. #define DisableMenuItem                        DisableItem
  88. #endif
  89.  
  90.  
  91. //////////
  92. //
  93. // constants
  94. //
  95. //////////
  96.  
  97. #define kInvalidFileRefNum                    -1                // an invalid file reference number
  98.  
  99. #define kDefaultFileTypeCount                100                // a generous guess at the number of file types we can open
  100.  
  101. // constants for selecting InitApplication phase
  102. enum {
  103.     kInitAppPhase_BeforeCreateFrameWindow     = 1L << 0,        // MDI frame window is not yet created
  104.     kInitAppPhase_AfterCreateFrameWindow    = 1L << 1,        // MDI frame window is already created
  105.     kInitAppPhase_BothPhases                = kInitAppPhase_BeforeCreateFrameWindow | kInitAppPhase_AfterCreateFrameWindow
  106. };
  107.  
  108. // constants for selecting StopApplication phase
  109. enum {
  110.     kStopAppPhase_BeforeDestroyWindows         = 1L << 0,        // movie windows are not yet torn down
  111.     kStopAppPhase_AfterDestroyWindows        = 1L << 1,        // movie windows are already torn down
  112.     kStopAppPhase_BothPhases                = kStopAppPhase_BeforeDestroyWindows | kStopAppPhase_AfterDestroyWindows
  113. };
  114.  
  115. enum {
  116.     kApplicationSignature                      = FOUR_CHAR_CODE('QTsh')
  117. };
  118.  
  119. // parameters to the SetMenuItemState function
  120. #if TARGET_OS_MAC
  121. #define kEnableMenuItem                        0x00000000L
  122. #define kDisableMenuItem                    0x00000001L
  123. #endif
  124.  
  125. #if TARGET_OS_WIN32
  126. #define kEnableMenuItem                        MF_ENABLED
  127. #define kDisableMenuItem                    MF_GRAYED
  128. #endif
  129.  
  130. // constants for standard modal dialog filter proc
  131. #define kMyButtonDelay                        8
  132. #define kReturnKey                            (char)0x0D    
  133. #define kEnterKey                            (char)0x03    
  134. #define kEscapeKey                            (char)0x1B    
  135. #define kPeriod                                '.'
  136.  
  137. // items in Save Changes dialog box
  138. #if TARGET_OS_MAC
  139. #define kSaveChanges                        1                        // save the changes before closing window
  140. #define kCancelClose                        2                        // no, don't close the window or save changes
  141. #define kDontSaveChanges                    3                        // discard any unsaved changes
  142. #define kOKButtonUserItem                    4
  143. #endif
  144.  
  145. #if TARGET_OS_WIN32
  146. #define kSaveChanges                        IDYES                    // save the changes before closing window
  147. #define kCancelClose                        IDCANCEL                // no, don't close the window or save changes
  148. #define kDontSaveChanges                    IDNO                    // discard any unsaved changes
  149. #endif
  150.  
  151. // default name of a movie created by "New" menu command
  152. #if TARGET_OS_MAC
  153. #define kNewMovieName                        "untitled.mov"
  154. #endif
  155. #if TARGET_OS_WIN32
  156. #define kNewMovieName                        "C:\\untitled.mov"
  157. #endif
  158.  
  159. // default window positions
  160. #ifndef kDefaultWindowX
  161. #define kDefaultWindowX                        100
  162. #endif
  163.  
  164. #ifndef kDefaultWindowY
  165. #define kDefaultWindowY                        100
  166. #endif
  167.  
  168.  
  169. /////////
  170. //
  171. // macros
  172. //
  173. //////////
  174.  
  175. // macros for converting Mac menu ID/menu item pairs into a single "menu item identifier"
  176. #define MENU_IDENTIFIER(menuID,menuItem)    ((menuID<<8)+(menuItem))
  177. #define MENU_ID(menuIdentifier)                ((menuIdentifier&0xff00)>>8)
  178. #define MENU_ITEM(menuIdentifier)            ((menuIdentifier&0x00ff))
  179.  
  180.  
  181. //////////
  182. //
  183. // data types
  184. //
  185. //////////
  186.  
  187. typedef const OSType *        QTFrameTypeListPtr;
  188.  
  189. #if TARGET_OS_MAC
  190. typedef MenuHandle            MenuReference;
  191. typedef WindowPtr            WindowReference;
  192. typedef NavObjectFilterUPP    QTFrameFileFilterUPP;
  193. #endif
  194.  
  195. #if TARGET_OS_WIN32
  196. typedef HMENU                MenuReference;
  197. typedef HWND                WindowReference;
  198. typedef FileFilterUPP        QTFrameFileFilterUPP;
  199. #endif
  200.  
  201.  
  202. //////////
  203. //
  204. // structures
  205. //
  206. //////////
  207.  
  208. // WindowObjectRecord is a data structure attached to a movie window.
  209. // We use this structure to associate data with any window presented.
  210. // If you have application-specific data that you want associated with
  211. // a movie or movie window, use the fAppData field to hold a handle to
  212. // that data.
  213.  
  214. typedef struct {
  215.     WindowReference            fWindow;            // the window
  216.     Movie                    fMovie;                // the movie
  217.     MovieController         fController;        // the movie controller
  218.     GraphicsImportComponent fGraphicsImporter;    // the graphics import component (if an image file)
  219.     FSSpec                    fFileFSSpec;        // location of the movie file
  220.     short                    fFileResID;            // the resource ID that the movie was loaded from
  221.     short                    fFileRefNum;        // the file reference number for the movie file
  222.     Boolean                    fCanResizeWindow;    // can the window be resized?
  223.     Boolean                    fIsDirty;            // has the movie data changed since the last save?
  224.     Boolean                    fIsQTVRMovie;        // is this a QuickTime VR movie?
  225.     QTVRInstance            fInstance;            // the QTVRInstance, if it's a QuickTime VR movie
  226.     OSType                    fObjectType;        // a tag indicating that the window object belongs to our application
  227.     Handle                    fAppData;            // a handle to application-specific window data
  228. } WindowObjectRecord, *WindowObjectPtr, **WindowObject;
  229.  
  230.  
  231. //////////
  232. //
  233. // function prototypes
  234. //       
  235. //////////
  236.  
  237. // the following functions are defined in MacFramework.c and/or WinFramework.c
  238. void                        QTFrame_QuitFramework (void);
  239. WindowReference                QTFrame_CreateMovieWindow (void);
  240. void                         QTFrame_DestroyMovieWindow (WindowReference theWindow);
  241. void                         QTFrame_ShowAboutBox (void);
  242. void                        QTFrame_GetDisplayName (char *thePathName, char *theDispName);
  243.  
  244. // the following functions are defined in ComFramework.c
  245. void                        QTFrame_HandleFileMenuItem (WindowReference theWindow, UInt16 theMenuItem);
  246. void                        HandleEditMenuItem (WindowReference theWindow, UInt16 theMenuItem);
  247. int                            QTFrame_AdjustMenus (WindowReference theWindow, MenuReference theMenu);
  248.  
  249. Boolean                     QTFrame_CreateNewMovie (void);
  250. Boolean                     OpenMovieInWindow (Movie theMovie, FSSpec *theFSSpec);
  251. MovieController                CreateController (Movie theMovie, WindowReference theWindow, Boolean theMoveWindow);
  252. OSErr                        QTFrame_SaveAsMovieFile (WindowReference theWindow);
  253. Boolean                     QTFrame_UpdateMovieFile (WindowReference theWindow);
  254. void                        QTFrame_IdleMovieWindows (void);
  255. void                        QTFrame_CloseMovieWindows (void);
  256. void                        QTFrame_CreateWindowObject (WindowReference theWindow);
  257. void                        QTFrame_CloseWindowObject (WindowObject theWindowObject);
  258.  
  259. WindowReference                QTFrame_GetFrontAppWindow (void);
  260. WindowReference                QTFrame_GetNextAppWindow (WindowReference theWindow);
  261. WindowReference                QTFrame_GetFrontMovieWindow (void);
  262. WindowReference                QTFrame_GetNextMovieWindow (WindowReference theWindow);
  263. WindowObject                QTFrame_GetWindowObjectFromFrontWindow (void);
  264. WindowObject                QTFrame_GetWindowObjectFromWindow (WindowReference theWnd);
  265. MovieController              QTFrame_GetMCFromFrontWindow (void);
  266. MovieController                QTFrame_GetMCFromWindow (WindowReference theWindow);
  267. QTVRInstance                QTFrame_GetQTVRInstanceFromFrontWindow (void);
  268. QTVRInstance                QTFrame_GetQTVRInstanceFromWindow (WindowReference theWindow);
  269. Handle                        QTFrame_GetAppDataFromFrontWindow (void);
  270. Handle                        QTFrame_GetAppDataFromWindow (WindowReference theWnd);
  271. Handle                        QTFrame_GetAppDataFromWindowObject (WindowObject theWindowObject);
  272. Boolean                     QTFrame_IsWindowObjectOurs (WindowObject theWindowObject);
  273. Boolean                        QTFrame_IsAppWindow (WindowReference theWindow);
  274. Boolean                        QTFrame_IsDocWindow (WindowReference theWindow);
  275. void                         ActivateController (WindowReference theWindow, Boolean IsActive);
  276.  
  277. void                        QTFrame_Beep (void);
  278. void                        QTFrame_SetMenuState (MenuReference theMenu, UInt16 theMenuRank, short theState);
  279. void                        QTFrame_SetMenuItemState (MenuReference theMenu, UInt16 theMenuItem, short theState);
  280. void                        QTFrame_SetMenuItemLabel (MenuReference theMenu, UInt16 theMenuItem, char *theText);
  281. void                        QTFrame_SetMenuItemCheck (MenuReference theMenu, UInt16 theMenuItem, Boolean theState);
  282. GrafPtr                        QTFrame_GetPortFromWindowReference (WindowReference theWindow);
  283. WindowReference                QTFrame_GetWindowReferenceFromPort (GrafPtr thePort);
  284. WindowPtr                    QTFrame_GetWindowFromWindowReference (WindowReference theWindow);
  285. short                        QTFrame_GetWindowWidth (WindowReference theWindow);
  286. void                        QTFrame_SetWindowTitleFromFSSpec (WindowReference theWindow, FSSpecPtr theFSSpecPtr, Boolean theAddToRecentDocs);
  287. void                        QTFrame_SizeWindowToMovie (WindowObject theWindowObject);
  288.  
  289. OSErr                        QTFrame_PutFile (ConstStr255Param thePrompt, ConstStr255Param theFileName, FSSpecPtr theFSSpecPtr, Boolean *theIsSelected, Boolean *theIsReplacing);
  290. OSErr                        QTFrame_GetOneFileWithPreview (short theNumTypes, QTFrameTypeListPtr theTypeList, FSSpecPtr theFSSpecPtr, void *theFilterProc);
  291. PASCAL_RTN void                QTFrame_HandleNavEvent (NavEventCallbackMessage theCallBackSelector, NavCBRecPtr theCallBackParms, void *theCallBackUD);
  292. Handle                        QTFrame_CreateOpenHandle (OSType theApplicationSignature, short theNumTypes, QTFrameTypeListPtr theTypeList);
  293. QTFrameFileFilterUPP        QTFrame_GetFileFilterUPP (ProcPtr theFileFilterProc);
  294. OSErr                        QTFrame_BuildFileTypeList (void);
  295. static void                    QTFrame_AddComponentFileTypes (OSType theComponentType, long *theNextIndex);
  296.  
  297. #if TARGET_OS_MAC
  298. PASCAL_RTN Boolean            QTFrame_FilterFiles (AEDesc *theItem, void *theInfo, void *theCallBackUD, NavFilterModes theFilterMode);
  299. #endif
  300. #if TARGET_OS_WIN32
  301. PASCAL_RTN Boolean            QTFrame_FilterFiles (CInfoPBPtr thePBPtr);
  302. void                        QTFrame_ConvertMacToWinRect (Rect *theMacRect, RECT *theWinRect);
  303. void                        QTFrame_ConvertWinToMacRect (RECT *theWinRect, Rect *theMacRect);
  304. #endif
  305.  
  306.  
  307. //////////
  308. //
  309. // application-specific function prototypes
  310. //
  311. // These are defined in the file ComApplication.c; both MacFramework.c and WinFramework.c
  312. // call these functions at specific times; you can use them to customize a specific application.
  313. //       
  314. //////////
  315.  
  316. void                        QTApp_Init (UInt32 theStartPhase);
  317. void                        QTApp_Stop (UInt32 theStopPhase);
  318. void                        QTApp_Idle (WindowReference theWindow);
  319. void                        Draw (WindowReference theWindow, Rect *theRefrehArea);
  320. void                         QTApp_HandleContentClick (WindowReference theWindow, EventRecord *theEvent);
  321. Boolean                        QTApp_HandleKeyPress (char theCharCode);
  322. Boolean                     QTApp_HandleMenu (UInt16 theMenuItem);
  323. void                        QTApp_AdjustMenus (WindowReference theWindow, MenuReference theMenu);
  324. Boolean                        QTApp_HandleEvent (EventRecord *theEvent);
  325. void                        SetupController (MovieController theMC);
  326. void                        QTApp_SetupWindowObject (WindowObject theWindowObject);
  327. void                        QTApp_RemoveWindowObject (WindowObject theWindowObject);
  328. PASCAL_RTN Boolean            myMCActionFilterProc (MovieController theMC, short theAction, void *theParams, long theRefCon);
  329.  
  330.